// 原生JavaScript处理
// 中间部分的高度设置
// let nav_height = document.getElementById("nav").offsetHeight;
// let content_height = document.getElementById("content").offsetHeight;
// let basicBox_height = (nav_height > content_height) ? nav_height : content_height;
// document.getElementById("basicBox").style.height = basicBox_height + 40 + "px";

// 获取用户参数
let userParameter = location.href;
let n1 = userParameter.length;
let n2 = userParameter.indexOf('=');
let userName = decodeURI(userParameter.substr(n2 + 1, n1 - n2));// userName就是用户参数

// Vue代码
const vm = new Vue({
    el: '#app',
    data() {
        return {
            userName: userName,
            isShowUserInfor: false,
            isShowToTop: false,
            lockData: [],
        }
    },
    methods: {
        getInfor: function () {
            let that = this;
            axios.get("//81.69.27.130/product/Lock/" + userName)
                .then(function (response) {
                    that.lockData = response.data;
                    for (let i in that.lockData) {
                        // 修改时间样式
                        let timeInfor = new Date(that.lockData[i].time);
                        that.lockData[i].time = timeInfor.toLocaleString();
                        // 转换状态
                        if (that.lockData[i].state == 0) {
                            that.lockData[i].state = '已关闭';
                            that.lockData[i].controlState = "开启";
                        } else {
                            that.lockData[i].state = '已开启';
                            that.lockData[i].controlState = "关闭";
                        }
                    }
                }, function (err) {
                    console.log(err);
                })
        },
        
        // 控制门锁开启、关闭
        changeState: function (id,controlState) {
            if(controlState == "开启"){
                axios.get('//81.69.27.130/product/lockopen/' + id)
                .then(function (response) {
                    setTimeout(function () {
                        alert(response.data.msg);
                        location.reload();
                    }, 500);
                }, function (err) {
                    // console.log(err);
                });
            }else if(controlState == "关闭"){
                axios.get("//81.69.27.130/product/lockclose/" + id)
                .then(function(response){
                    setTimeout(function(){
                        alert(response.data.msg);
                        location.reload();
                    },500)
                })
            }
        },

        getManage: function(){
            location.href = 'lockmanage.html?' + 'user=' + encodeURI(userName);
        },
        logger: function(){
            location.href = 'logger.html?' + 'user=' + encodeURI(userName);
        },

        // 根据id查日志
        // getAllState:function(){
        //     let lockId = $("#lockId").val();
        //     axios.get("")

        // },
        // getIdState: function(){

        // }

    },
    mounted() {
        this.getInfor();
    },
    created() {
        let _this = this;
        window.onscroll = function () {
            // 滚动条滚动的距离
            let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            if (scrollTop >= 500) {
                _this.isShowToTop = true;
            } else {
                _this.isShowToTop = false;
            }
        }
    }
})
// jQuery代码
$(document).ready(function () {
    $('#nav').on('click', '.navItermA', function () {
        $(this).removeClass("navItermA").siblings().addClass("navItermA");
        $(this).addClass("navItermB").siblings().removeClass("navItermB");
    });
})